package com.geek.hotupdate.beans;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledUpdater {
    private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
    private long initialDelayInSeconds;
    private long periodInSeconds;
    private Runnable runnable;

    public ScheduledUpdater(long initialDelayInSeconds, long periodInSeconds, Runnable runnable) {
        this.initialDelayInSeconds = initialDelayInSeconds;
        this.periodInSeconds = periodInSeconds;
        this.runnable = runnable;
    }

    public void run() {
        executor.scheduleAtFixedRate(runnable, this.initialDelayInSeconds, this.periodInSeconds, TimeUnit.SECONDS);
    }
}